<cfoutput>
<cfif not find('/', mid(form.newApplicationDirectory,1,1))>
	<cfset form.newApplicationDirectory = "/#form.newApplicationDirectory#"/>
</cfif>
<cfset newApplicationDirectoryDotPath = replace(form.newApplicationDirectory,"/",".","ALL") />
<cfset newApplicationDirectoryDotPath = mid(replace(form.newApplicationDirectory,"/",".","ALL"),2,len(newApplicationDirectoryDotPath)) />

<cfsavecontent variable="content">templateDirectory=/appgenerator/wstemplate
newApplicationName=#form.newApplicationName#
newApplicationDirectory=#form.newApplicationDirectory#
newApplicationDirectoryDotPath=#newApplicationDirectoryDotPath#
datasource=#form.datasource#</cfsavecontent>
</cfoutput>
<cffile action="write" file="#expandpath('newwsapp.properties')#" output="#replace(content,"\","\\","ALL")#"/>
<cfif not directoryexists( expandpath(form.newApplicationDirectory) )>
	<cfant buildFile="#expandpath('newwsapp.xml')#"
	 defaultDirectory="seemsTobeIgnoredButMustBePresent"
	 anthome="alsoSeemsToBeIgnoredButMayNeedToHaveAnEnvironmentVariableSetup"
	 messages="result"
	 target="newapp"
	/> 
	
	<cfif find("BUILD FAILED", result)>
		<h1>There was an error</h1>
		<cfdump var="#result#">
		<a href="newwsapp.cfm">Go Back</a>
		<cfabort>
	</cfif>
	<h1>Application successfully created!</h1>
	<i>Info:<br>
	<cfdump var="#result#"></i>
	<br>
	<br>
<cfelse>
	<h1>Application already exists.</h1>
</cfif>
<cfoutput>
<a href="../#form.newApplicationDirectory#/script" target="_blank">Click here to go to the application</a><br>
<a href="index.cfm?reinit">Click here to go back to the Application Generator main screen</a><br>
</cfoutput>
